package com.flyxiaozhu.erp.core.repositories;

import com.flyxiaozhu.erp.core.entities.GoodsOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.LockModeType;

/**
 * @author flyxiaozhu
 * @date 2019-04-26 15:44
 */
public interface GoodsOrderRepository extends JpaRepository<GoodsOrder, Long>, JpaSpecificationExecutor<GoodsOrder> {
    @Query("select order from GoodsOrder order where order.outTradeNo = ?1")
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    GoodsOrder findByOutTradeNoOnLock(String outTradeNo);

    @Query("select order from GoodsOrder order where order.id = ?1")
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    GoodsOrder findByIdOnLock(long id);
}
